package com.heima.wemedia.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.model.common.dtos.common.PageDto;
import com.heima.model.common.dtos.common.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.wemedia.pojos.WmSensitive;
import com.heima.wemedia.service.WmSensitiveService;
import com.heima.wemedia.mapper.WmSensitiveMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author Fu319
* @description 针对表【wm_sensitive(敏感词信息表)】的数据库操作Service实现
* @createDate 2025-04-04 22:25:15
*/
@Service
public class WmSensitiveServiceImpl extends ServiceImpl<WmSensitiveMapper, WmSensitive> implements WmSensitiveService{
    @Autowired
    private WmSensitiveMapper wmSensitiveMapper;

    @Override
    public ResponseResult pageList(PageDto pageDto) {
        //检验参数
        if(pageDto==null){
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
        }
        //准备分页参数
        Page<WmSensitive> page = new Page<>(pageDto.getPage(),pageDto.getSize());
        LambdaQueryWrapper<WmSensitive> wrapper = new LambdaQueryWrapper<>();
        //设置查询条件
        if(StringUtils.isNotEmpty(pageDto.getName())){
            wrapper.like(WmSensitive::getSensitives,pageDto.getName());
        }
        //根据创建时间倒序
        wrapper.orderByDesc(WmSensitive::getCreatedTime);
        //调用mapper获取分页数据
        Page<WmSensitive> wmSensitivePage = wmSensitiveMapper.selectPage(page, wrapper);
        return ResponseResult.okResult(wmSensitivePage.getRecords());
    }
}




